package cn.it.controller;

import cn.it.entity.PageResult;
import cn.it.entity.QueryPageBean;
import cn.it.entity.Result;
import cn.it.pojo.Company;
import cn.it.service.CompanyService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/company")
public class CompanyController {

    @Reference
    private CompanyService companyService;

    @RequestMapping(value = "/addAddress", name = "新增地图")
    public Result addAddress(@RequestBody Company company) {

        try {
            companyService.addAddress(company);
            return new Result(true, "添加位置信息成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "添加位置信息失败");
        }
    }


    @RequestMapping(value = "/findPage", name = "分页查询")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return  companyService.findPage(queryPageBean);
    }

    @RequestMapping(value = "/delete", name = "分页查询")
    public Result delete(Integer id) {
        try {
            companyService.delete(id);
            return new Result(true,"删除地址成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"删除地址失败");
        }
    }

    @RequestMapping(value = "/findAll", name = "查询所有")
    public Result findAll() {
        try {
            List<Company> companyList =companyService.findAll();
            return new Result(true,"获取分布图数据成功",companyList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"获取分布图数据失败");
        }
    }
}
